<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="如何上传自己的UI组件包, 小康,xkloveme,博客">
    <meta name="description" content="开篇
西风吹老洞庭波，一夜湘君白发多。醉后不知天在水，满船清梦压星河。

前言身为程序员,还没有自己的包,总感觉缺点什么,女朋友和包至少占一样吧.正如上战场没有扛枪的士兵,吃饭少了筷子一样,令人心情不愉悦.同时经常会有面试官会问一个犀利的问">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>如何上传自己的UI组件包 | 小康之家</title>
    <link rel="icon" type="image/x-icon, image/vnd.microsoft.icon" href="/favicon.ico">

    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/font-awesome/5.12.1/css/all.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/materialize/1.0.0/css/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/aos/3.0.0-beta.6/aos.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/animate.css/3.5.1/animate.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/lightgallery/1.6.11/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">
    
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    
<meta name="generator" content="Hexo 4.2.0"><link rel="alternate" href="/atom.xml" title="小康之家" type="application/atom+xml">
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>


<body >
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper head-container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">小康之家</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友情链接</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>

<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">小康之家</div>
        <div class="logo-desc">
            
            小康のblog
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/xkloveme" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>

        </div>

        
            <style>
  .nav-transparent .github-corner {
    display: none !important;
  }

  .github-corner {
    position: absolute;
    z-index: 10;
    top: 0;
    right: 0;
    border: 0;
    transform: scale(1.1);
  }

  .github-corner svg {
    color: #027aff;
    fill: #fff;
    height: 64px;
    width: 64px;
  }

  .github-corner:hover .octo-arm {
    animation: a 0.56s ease-in-out;
  }

  .github-corner .octo-arm {
    animation: none;
  }

  @keyframes a {
    0%,
    to {
      transform: rotate(0);
    }
    20%,
    60% {
      transform: rotate(-25deg);
    }
    40%,
    80% {
      transform: rotate(10deg);
    }
  }
</style>

<a
  href="https://github.com/xkloveme"
  class="github-corner tooltipped hide-on-med-and-down"
  target="_blank"
  data-tooltip="Fork Me"
  data-position="left"
  data-delay="50"
>
  <svg viewBox="0 0 250 250" aria-hidden="true">
    <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
    <path
      d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
      fill="currentColor"
      style="transform-origin: 130px 106px;"
      class="octo-arm"
    ></path>
    <path
      d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
      fill="currentColor"
      class="octo-body"
    ></path>
  </svg>
</a>

        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('https://picsum.photos/600/300?t=prjo6bwjkj')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <div class="description center-align post-title">
                        如何上传自己的UI组件包
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="https://cdn.bootcss.com/tocbot/4.10.0/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #toc-content .is-active-link::before {
        background-color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/vue/">
                                <span class="chip bg-color">vue</span>
                            </a>
                        
                            <a href="/tags/GitHub/">
                                <span class="chip bg-color">GitHub</span>
                            </a>
                        
                            <a href="/tags/%E6%95%99%E7%A8%8B/">
                                <span class="chip bg-color">教程</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/%E5%89%8D%E7%AB%AF/" class="post-category">
                                前端
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2019-10-11
                </div>
                

                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    2k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-clock fa-fw"></i>阅读时长:&nbsp;&nbsp;
                    8 分
                </div>
                
				
                
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="far fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
            
        </div>
        <hr class="clearfix">
        <div class="card-content article-card-content">
            <div id="articleContent">
                <h1 id="开篇"><a href="#开篇" class="headerlink" title="开篇"></a>开篇</h1><blockquote>
<p>西风吹老洞庭波，一夜湘君白发多。<br>醉后不知天在水，满船清梦压星河。</p>
</blockquote>
<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p><strong>身为程序员,还没有自己的包,总感觉缺点什么,女朋友和包至少占一样吧.正如上战场没有扛枪的士兵,吃饭少了筷子一样,令人心情不愉悦.同时经常会有面试官会问一个犀利的问题,你有自己开源项目么?你写过公司自己的 UI 组件么?如同雷劈,总觉得比别人矮一截,那么今天就以<a href="https://hy.hekr.me/hk-ui/web/index.html" target="_blank" rel="noopener">hekr-ui</a>为例,介绍一下如何打造自己的 UI 库吧</strong></p>
<ul>
<li><a href="https://hy.hekr.me/hk-ui/web/index.html" target="_blank" rel="noopener">文档地址</a></li>
<li><a href="https://github.com/xkloveme/hk-ui" target="_blank" rel="noopener">项目源码</a></li>
</ul>
<h2 id="选型"><a href="#选型" class="headerlink" title="选型"></a>选型</h2><blockquote>
<p>我们的目标是构建一个以<code>Vue</code>为基础基于<code>element-ui</code>的 UI 框架</p>
</blockquote>
<ul>
<li>文档选用 <code>Vuepress</code> 构建,简单便捷</li>
<li>打包选择 <code>gitlab CI</code> ,本文以 <code>travis</code> 为例</li>
<li>初始化采用<code>vue-cli 3.0</code>、<code>pug</code>和<code>sass</code>等相关依赖和插件(自行探索)</li>
</ul>
<h2 id="目的"><a href="#目的" class="headerlink" title="目的"></a>目的</h2><ol>
<li>快速构建属于 ❤️ 自己<code>npm</code>库</li>
<li>熟悉打包 📦 命令及其语法</li>
<li>熟练掌握自动化 👷 构建</li>
<li>为社区贡献自己一份脚印 👣</li>
</ol>
<h1 id="初步构思"><a href="#初步构思" class="headerlink" title="初步构思"></a>初步构思</h1><h2 id="启动一个项目"><a href="#启动一个项目" class="headerlink" title="启动一个项目"></a>启动一个项目</h2><h3 id="1-初始化一个项目"><a href="#1-初始化一个项目" class="headerlink" title="1.初始化一个项目"></a>1.初始化一个项目</h3><blockquote>
<p>这里推荐使用<a href="https://cli.vuejs.org/zh/guide/creating-a-project.html#vue-create" target="_blank" rel="noopener"><code>Vue CLI</code></a> 来进行快速构建</p>
</blockquote>
<p><img src="https://s2.ax1x.com/2019/10/10/uThubn.jpg" alt="初始化.jpg"></p>
<pre class=" language-bash"><code class="language-bash">vue create hekr-ui</code></pre>
<p>我们选择默认配置就可以了</p>
<h3 id="2-关联代码到你的库"><a href="#2-关联代码到你的库" class="headerlink" title="2.关联代码到你的库"></a>2.关联代码到你的库</h3><blockquote>
<p><code>git</code>可以很好对代码版本进行管理</p>
</blockquote>
<ul>
<li>当你初始化库时</li>
</ul>
<pre class=" language-bash"><code class="language-bash"><span class="token keyword">echo</span> <span class="token string">"# hekr-ui"</span> <span class="token operator">>></span> README.md
<span class="token function">git</span> init
<span class="token function">git</span> add README.md
<span class="token function">git</span> commit -m <span class="token string">"first commit"</span>
<span class="token function">git</span> remote add origin https://github.com/xkloveme/hekr-ui.git
<span class="token function">git</span> push -u origin master</code></pre>
<ul>
<li>关联本地库时</li>
</ul>
<pre class=" language-bash"><code class="language-bash"><span class="token function">git</span> remote add origin https://github.com/xkloveme/hekr-ui.git
<span class="token function">git</span> push -u origin master</code></pre>
<p>当然我们选择第二种.记得把<code>node_modules</code>忽略</p>
<h2 id="配置你的项目"><a href="#配置你的项目" class="headerlink" title="配置你的项目"></a>配置你的项目</h2><h3 id="1-添加相关依赖"><a href="#1-添加相关依赖" class="headerlink" title="1.添加相关依赖"></a>1.添加相关依赖</h3><blockquote>
<p>本文以<code>yarn</code>为主,当然<code>npm</code>也是 👌OK 的</p>
</blockquote>
<p>我们以<code>vuepress</code>为主编写文档,当然这是非必须的,如果您只想发一个包,可以省略此步,必要的<code>demo</code>和测试会有极大的方便</p>
<pre class=" language-bash"><code class="language-bash"><span class="token comment" spellcheck="true"># 将 VuePress 作为一个本地依赖安装</span>
yarn add -D vuepress <span class="token comment" spellcheck="true"># 或者：npm install -D vuepress</span>

<span class="token comment" spellcheck="true"># 新建一个 docs 文件夹</span>
<span class="token function">mkdir</span> docs

<span class="token comment" spellcheck="true"># 新建一个 markdown 文件</span>
<span class="token keyword">echo</span> <span class="token string">'# Hello VuePress!'</span> <span class="token operator">></span> docs/README.md

<span class="token comment" spellcheck="true"># 开始写作</span>
npx vuepress dev docs</code></pre>
<p>接着，在 <code>package.json</code> 里加一些脚本:</p>
<pre class=" language-json"><code class="language-json"><span class="token punctuation">{</span>
  <span class="token property">"scripts"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">"docs:dev"</span><span class="token operator">:</span> <span class="token string">"vuepress dev docs"</span><span class="token punctuation">,</span>
    <span class="token property">"docs:build"</span><span class="token operator">:</span> <span class="token string">"vuepress build docs"</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre>
<p>然后就可以开始写作了:</p>
<pre class=" language-bash"><code class="language-bash">yarn docs:dev <span class="token comment" spellcheck="true"># 或者：npm run docs:dev</span></code></pre>
<p>要生成静态的 HTML 文件，运行：</p>
<pre class=" language-bash"><code class="language-bash">yarn docs:build <span class="token comment" spellcheck="true"># 或者：npm run docs:build</span></code></pre>
<p>添加其他依赖,常用语法</p>
<pre class=" language-bash"><code class="language-bash">// 安装指定包
yarn add ***
// 安装所有包,注意和npm的区别
yarn</code></pre>
<p>注意 ⚠️ 这两者的区别<code>dependencies</code>和<code>devDependencies</code></p>
<ol>
<li><code>--save</code> 将依赖的名称、版本要求添加到 <code>dependencies</code></li>
<li><code>--save-dev</code> 将依赖的名称、版本要求添加到 <code>devDependencies</code></li>
</ol>
<h3 id="2-一些约定俗成的目录结构"><a href="#2-一些约定俗成的目录结构" class="headerlink" title="2.一些约定俗成的目录结构"></a>2.一些约定俗成的目录结构</h3><ul>
<li>在使用<code>vuepress</code>开发时,约定了一些目录结构</li>
</ul>
<pre class=" language-docs"><code class="language-docs">.
├── docs
│   ├── .vuepress (可选的)
│   │   ├── components (可选的)
│   │   ├── theme (可选的)
│   │   │   └── Layout.vue
│   │   ├── public (可选的)
│   │   ├── styles (可选的)
│   │   │   ├── index.styl
│   │   │   └── palette.styl
│   │   ├── templates (可选的, 谨慎配置)
│   │   │   ├── dev.html
│   │   │   └── ssr.html
│   │   ├── config.js (可选的)
│   │   └── enhanceApp.js (可选的)
│   │
│   ├── README.md
│   ├── guide
│   │   └── README.md
│   └── config.md
│
└── package.json</code></pre>
<ul>
<li>在本项目中目录结构为</li>
</ul>
<p><img src="https://s2.ax1x.com/2019/10/10/uThQU0.jpg" alt="结构.jpg"></p>
<pre class=" language-tree"><code class="language-tree">template
├─ docs
│    └─ .vuepress            # 配置、演示组件、静态资源
│    │    ├─ compnents        # 演示组件
│    │    |    └─ demo          # demo组件
│    │    ├─ public           # 静态资源
│    │    |    └─ images        # 图片文件
│    │    |    └─ scss          # 样式文件
│    │    ├─ config.js        # 配置文件
│    │    └─ enhanceApp       # 引入文件
|    ├─ compnent             # 组件md文件
|    └─ README              # 首页md
├─ packages
│    ├─ index.js             # 组件index.js
│    └─ hk-countup           # countup组件
├─ public
└─ package.json</code></pre>
<h3 id="3-修改你的package-json文件"><a href="#3-修改你的package-json文件" class="headerlink" title="3.修改你的package.json文件"></a>3.修改你的<code>package.json</code>文件</h3><blockquote>
<p>这个文件是项目的灵魂 👻,是最重要的文件之一.具体字段参考<a href="http://javascript.ruanyifeng.com/nodejs/packagejson.html" target="_blank" rel="noopener">packagejson</a></p>
</blockquote>
<p><img src="https://s2.ax1x.com/2019/10/10/uThl5V.jpg" alt="目录.jpg"></p>
<ul>
<li>修改主入口<code>main</code></li>
</ul>
<blockquote>
<p><code>main</code>字段指定了加载的入口文件，<code>require(&#39;moduleName&#39;)</code>就会加载这个文件。这个字段的默认值是模块根目录下面的<code>index.js</code>。</p>
</blockquote>
<pre class=" language-bash"><code class="language-bash"><span class="token string">"main"</span><span class="token keyword">:</span> <span class="token string">"dist/hekr-ui.umd.min.js"</span></code></pre>
<blockquote>
<p>你可以通过下面的命令将一个单独的入口构建为一个库</p>
</blockquote>
<pre class=" language-bash"><code class="language-bash">vue-cli-service build --target lib --name myLib <span class="token punctuation">[</span>entry<span class="token punctuation">]</span></code></pre>
<p>运行结果为:</p>
<pre class=" language-bash"><code class="language-bash">  File                     Size                     Gzipped

  dist/hk-ui.umd.min.js    13.64 KiB                5.31 KiB
  dist/hk-ui.umd.js        43.87 KiB                11.37 KiB
  dist/hk-ui.common.js     43.49 KiB                11.25 KiB
  dist/hk-ui.css           0.54 KiB                 0.29 KiB</code></pre>
<ul>
<li>添加<code>lib</code>命令</li>
</ul>
<pre class=" language-bash"><code class="language-bash">    <span class="token string">"lib"</span><span class="token keyword">:</span> <span class="token string">"vue-cli-service build --target lib --name hk-ui --dest dist ./src/packages/index.js"</span></code></pre>
<p>这个入口可以是一个 <code>.js</code> 或一个 <code>.vue</code> 文件。如果没有指定入口，则会使用 <code>src/App.vue</code>。</p>
<p>构建一个库会输出：</p>
<ul>
<li><p><code>dist/myLib.common.js</code>：一个给打包器用的 CommonJS 包 (不幸的是，webpack 目前还并没有支持 ES modules 输出格式的包)</p>
</li>
<li><p><code>dist/myLib.umd.js</code>：一个直接给浏览器或 AMD loader 使用的 UMD 包</p>
</li>
<li><p><code>dist/myLib.umd.min.js</code>：压缩后的 UMD 构建版本</p>
</li>
<li><p><code>dist/myLib.css</code>：提取出来的 CSS 文件 (可以通过在 <code>vue.config.js</code> 中设置 <code>css: { extract: false }</code> 强制内联)</p>
</li>
</ul>
<h3 id="4-文档配置"><a href="#4-文档配置" class="headerlink" title="4. 文档配置"></a>4. 文档配置</h3><p><img src="https://s2.ax1x.com/2019/10/10/uTIdVs.jpg" alt="文档.jpg"></p>
<blockquote>
<p>项目启动之后需要我们配置我们的<code>vuepress</code></p>
</blockquote>
<pre class=" language-js"><code class="language-js"><span class="token comment" spellcheck="true">/*
 * @describe: 配置文件 config.js
 * @Author: superDragon
 * @Date: 2019-10-09 23:25:49
 * @LastEditors: superDragon
 * @LastEditTime: 2019-10-10 18:49:25
 */</span>
<span class="token keyword">let</span> component <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">"hk-button"</span><span class="token punctuation">,</span> <span class="token string">"hk-card"</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
  base<span class="token punctuation">:</span> <span class="token string">"/hekr-ui/"</span><span class="token punctuation">,</span>
  title<span class="token punctuation">:</span> <span class="token string">"hekr-ui"</span><span class="token punctuation">,</span>
  description<span class="token punctuation">:</span> <span class="token string">"hekr-ui"</span><span class="token punctuation">,</span>
  themeConfig<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    nav<span class="token punctuation">:</span> <span class="token punctuation">[</span>
      <span class="token punctuation">{</span> text<span class="token punctuation">:</span> <span class="token string">"首页"</span><span class="token punctuation">,</span> link<span class="token punctuation">:</span> <span class="token string">"/"</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">{</span>
        text<span class="token punctuation">:</span> <span class="token string">"组件"</span><span class="token punctuation">,</span>
        link<span class="token punctuation">:</span> <span class="token string">"/component/hk-button"</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">]</span><span class="token punctuation">,</span>
    sidebar<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      <span class="token string">"/component/"</span><span class="token punctuation">:</span> component
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    lastUpdated<span class="token punctuation">:</span> <span class="token string">"最后更新"</span><span class="token punctuation">,</span>
    repo<span class="token punctuation">:</span> <span class="token string">""</span><span class="token punctuation">,</span>
    repoLabel<span class="token punctuation">:</span> <span class="token string">"GitLab"</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  plugins<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
  serviceWorker<span class="token punctuation">:</span> <span class="token boolean">true</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span></code></pre>
<p>当我们能够成功运行下面时</p>
<pre class=" language-js"><code class="language-js">    <span class="token string">"docs:dev"</span><span class="token punctuation">:</span> <span class="token string">"vuepress dev docs"</span><span class="token punctuation">,</span>
    <span class="token string">"docs:build"</span><span class="token punctuation">:</span> <span class="token string">"vuepress build docs"</span><span class="token punctuation">,</span></code></pre>
<ul>
<li>本地运行</li>
</ul>
<pre><code>yarn docs:dev # 或者：npm run docs:dev</code></pre><ul>
<li>打包</li>
</ul>
<pre><code>yarn docs:build # 或者：npm run docs:build</code></pre><h3 id="5-持续集成"><a href="#5-持续集成" class="headerlink" title="5.持续集成"></a>5.持续集成</h3><blockquote>
<p>以<code>GitHub Pages</code> 和<code>Travis CI</code> 为例</p>
</blockquote>
<ul>
<li>打包后放置在项目的 <code>docs</code> 目录中的<code>dist</code>中,注意 ⚠️ 区分；</li>
<li>使用的是默认的构建输出位置；</li>
<li>VuePress 以本地依赖的形式被安装到你的项目中，并且配置了如下的 npm scripts:</li>
</ul>
<pre class=" language-json"><code class="language-json"><span class="token punctuation">{</span>
  <span class="token property">"scripts"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">"docs:build"</span><span class="token operator">:</span> <span class="token string">"vuepress build docs"</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre>
<ol>
<li><p>在 <code>docs/.vuepress/config.js</code> 中设置正确的 <code>base</code>这里我们设置<code>/hekr-ui/</code> 🌿。</p>
<p>如果你打算发布到 <code>https://&lt;USERNAME&gt;.github.io/</code>，则可以省略这一步，因为 <code>base</code> 默认即是 <code>&quot;/&quot;</code>。</p>
<p>如果你打算发布到 <code>https://&lt;USERNAME&gt;.github.io/&lt;REPO&gt;/</code>（也就是说你的仓库在 <code>https://github.com/&lt;USERNAME&gt;/&lt;REPO&gt;</code>），则将 <code>base</code> 设置为 <code>&quot;/&lt;REPO&gt;/&quot;</code>。</p>
</li>
<li><p>在你的项目中，创建一个如下的 <code>.travis.yml</code> 文件 📃:</p>
</li>
</ol>
<pre class=" language-yml"><code class="language-yml">language: node_js
node_js:
  - "8"

install:
  - npm install

script:
  - npm run build

after_success:
  - cd ./docs/.vuepress/dist
  - git init
  - git config --global user.name "${U_NAME}"
  - git config --global user.email "${U_EMAIL}"
  - git add .
  - git commit -m "👷‍Automatically update from travis-ci 👷‍"
  - git push --quiet --force  "https://${GH_TOKEN}@${GH_REF}" master:${P_BRANCH}

branches:
  only:
    - master

notifications:
  email:
    - xkloveme@163.com
  on_failure: always

# Note: you should set Environment Variables here or 'Settings' on travis-ci.org
env:
  global:
    # 我将其添加到了travis-ci的环境变量中
    - U_NAME: xkloveme
    - U_EMAIL: xkloveme@qq.com
    - P_BRANCH: gh-pages
    - GH_REF: github.com/xkloveme/vue-v-xxx.git</code></pre>
<ol start="3">
<li>注册<code>github</code>、<code>travis</code>和配置<code>travis</code>相关,启用构建,自行<code>Google</code><a href="https://docs.travis-ci.com/user/deployment/pages/" target="_blank" rel="noopener">传送门</a></li>
<li>更多配置参考<a href="https://vuepress.vuejs.org/zh/guide/deploy.html" target="_blank" rel="noopener">vuepress 部署</a></li>
</ol>
<h1 id="实践"><a href="#实践" class="headerlink" title="实践"></a>实践</h1><h2 id="完善组件并打包"><a href="#完善组件并打包" class="headerlink" title="完善组件并打包"></a>完善组件并打包</h2><blockquote>
<p>以编写<code>hk-button</code>组件为例,并导出</p>
</blockquote>
<ol>
<li>添加组件及导出</li>
</ol>
<pre class=" language-vue"><code class="language-vue"><template lang="pug">
el-tooltip(effect="dark" v-if="tips" :content="tips" placement="top-start")
  el-button.hk-button(:size="size" :type="type" v-bind="$attrs" @click="handleClick")
    slot
el-button.hk-button(:size="size" v-else :type="type" v-bind="$attrs" @click="handleClick")
  slot
</template>

<script>
import { Debounce } from "./../util/debounce";
export default {
  name: "hk-button",
  props: {
    type: {
      type: String,
      default: "primary"
    },
    size: {
      type: String,
      default: "medium"
    },
    tips: {
      type: String,
      default: null
    }
  },
  methods: {
    handleClick: Debounce(function(e) {
      this.$emit("click", e);
    }, 200)
  }
};
</script>

<style lang="scss">
.hk-button {
  i + span {
    padding-left: 10px;
  }
}
</style></code></pre>
<ol start="2">
<li>导出组件</li>
</ol>
<pre class=" language-js"><code class="language-js"><span class="token keyword">import</span> HkButton <span class="token keyword">from</span> <span class="token string">"./hk-button"</span><span class="token punctuation">;</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> HkButton<span class="token punctuation">;</span></code></pre>
<ol start="3">
<li>导出为<code>install</code></li>
</ol>
<pre class=" language-js"><code class="language-js"><span class="token comment" spellcheck="true">/*
 * @describe: 主入口,导出install
 * @Author: superDragon
 * @Date: 2019-10-09 23:21:11
 * @LastEditors: superDragon
 * @LastEditTime: 2019-10-10 19:09:57
 */</span>
<span class="token keyword">import</span> HkButton <span class="token keyword">from</span> <span class="token string">"./hk-button"</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> HKcard <span class="token keyword">from</span> <span class="token string">"./hk-card"</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> install <span class="token operator">=</span> Vue <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">{</span>
  Vue<span class="token punctuation">.</span><span class="token function">component</span><span class="token punctuation">(</span>HkButton<span class="token punctuation">.</span>name<span class="token punctuation">,</span> HkButton<span class="token punctuation">)</span><span class="token punctuation">;</span>
  Vue<span class="token punctuation">.</span><span class="token function">component</span><span class="token punctuation">(</span>HKcard<span class="token punctuation">.</span>name<span class="token punctuation">,</span> HKcard<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">typeof</span> window <span class="token operator">!==</span> <span class="token string">"undefined"</span> <span class="token operator">&amp;&amp;</span> window<span class="token punctuation">.</span>Vue<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token function">install</span><span class="token punctuation">(</span>window<span class="token punctuation">.</span>Vue<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token punctuation">{</span> HkButton<span class="token punctuation">,</span> HKcard <span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span> install <span class="token punctuation">}</span><span class="token punctuation">;</span></code></pre>
<h2 id="上传自己的npm"><a href="#上传自己的npm" class="headerlink" title="上传自己的npm"></a>上传自己的<code>npm</code></h2><h3 id="注册-®️-并切换到官方npm源"><a href="#注册-®️-并切换到官方npm源" class="headerlink" title="注册 ®️ 并切换到官方npm源"></a>注册 ®️ 并切换到官方<code>npm</code>源</h3><p><img src="https://s2.ax1x.com/2019/10/10/uTjYY4.jpg" alt="换源.jpg"></p>
<h3 id="注册登陆npm"><a href="#注册登陆npm" class="headerlink" title="注册登陆npm"></a>注册登陆<code>npm</code></h3><pre class=" language-bash"><code class="language-bash"><span class="token function">npm</span> adduser        //回车后,弹出Username:
Username:          //输入你在官网注册时的用户名,回车
Password:          //输入官网注册的密码,密码看不见,请确保你输的密码正确, 回车
Email:<span class="token punctuation">(</span>this is Public<span class="token punctuation">)</span>    //输入官网注册时绑定的邮箱,回车</code></pre>
<h3 id="上传"><a href="#上传" class="headerlink" title="上传"></a>上传</h3><pre class=" language-bash"><code class="language-bash"><span class="token function">npm</span> publish        //此处上传命令,回车</code></pre>
<p><img src="https://s2.ax1x.com/2019/10/10/uTvZB6.jpg" alt="发布.jpg"></p>
<p>这样一个<code>hekr-ui</code>就发布完成了</p>
<h3 id="撤销"><a href="#撤销" class="headerlink" title="撤销"></a>撤销</h3><blockquote>
<p>24 小时内撤销也是很简单的.</p>
</blockquote>
<pre class=" language-bash"><code class="language-bash"><span class="token function">npm</span> unpublish --force</code></pre>
<h1 id="大功告成"><a href="#大功告成" class="headerlink" title="大功告成"></a>大功告成</h1><blockquote>
<p>Let’s enjoy the taste of life, if we feel, the more we will live longer.</p>
</blockquote>
<p>觉得不错的话给个<code>star</code></p>
<ul>
<li>本文演示库地址<a href="https://github.com/xkloveme/hekr-ui" target="_blank" rel="noopener">hekr-ui</a></li>
<li><a href="https://hy.hekr.me/hk-ui/web/index.html" target="_blank" rel="noopener">文档地址</a></li>
<li><a href="https://github.com/xkloveme/hk-ui" target="_blank" rel="noopener">项目源码</a></li>
</ul>

            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="http://jixioakang.com" rel="external nofollow noreferrer">xkloveme</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="http://jixioakang.com/2019/10/11/2019-10-12-ru-he-shang-chuan-zi-ji-de-ui-zu-jian-bao/">http://jixioakang.com/2019/10/11/2019-10-12-ru-he-shang-chuan-zi-ji-de-ui-zu-jian-bao/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="http://jixioakang.com" target="_blank">xkloveme</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/vue/">
                                    <span class="chip bg-color">vue</span>
                                </a>
                            
                                <a href="/tags/GitHub/">
                                    <span class="chip bg-color">GitHub</span>
                                </a>
                            
                                <a href="/tags/%E6%95%99%E7%A8%8B/">
                                    <span class="chip bg-color">教程</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">

<div id="article-share">
    
    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
  #reward {
    margin: 40px 0;
    text-align: center;
  }

  #reward .reward-link {
    font-size: 1.4rem;
    line-height: 38px;
  }

  #reward .btn-floating:hover {
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
  }

  #rewardModal {
    width: 320px;
  }

  #rewardModal .reward-title {
    margin: 15px auto;
    padding-bottom: 5px;
  }

  #rewardModal .modal-content {
    padding: 10px;
  }

  #rewardModal .close {
    position: absolute;
    right: 15px;
    top: 15px;
    color: rgba(0, 0, 0, 0.5);
    font-size: 1.3rem;
    line-height: 20px;
    cursor: pointer;
  }

  #rewardModal .close:hover {
    color: #ef5350;
    transform: scale(1.3);
    -moz-transform: scale(1.3);
    -webkit-transform: scale(1.3);
    -o-transform: scale(1.3);
  }

  #rewardModal .reward-tabs {
    margin: 0 auto;
    width: 210px;
  }

  .reward-tabs .tabs {
    height: 38px;
    margin: 10px auto;
    padding-left: 0;
  }

  .reward-content ul {
    padding-left: 0 !important;
  }

  .reward-tabs .tabs .tab {
    height: 38px;
    line-height: 38px;
  }

  .reward-tabs .tab a {
    color: #fff;
    background-color: #ccc;
  }

  .reward-tabs .tab a:hover {
    background-color: #ccc;
    color: #fff;
  }

  .reward-tabs .wechat-tab .active {
    color: #fff !important;
    background-color: #22ab38 !important;
  }

  .reward-tabs .alipay-tab .active {
    color: #fff !important;
    background-color: #019fe8 !important;
  }

  .reward-tabs .reward-img {
    width: 210px;
  }
</style>

<div id="reward">
  <a
    href="#rewardModal"
    class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red"
    >赏</a
  >

  <!-- Modal Structure -->
  <div id="rewardModal" class="modal">
    <div class="modal-content">
      <a class="close modal-close"><i class="fas fa-times"></i></a>
      <h4 class="reward-title">你的赏识是我前进的动力</h4>
      <div class="reward-content">
        <div class="reward-tabs">
          <ul class="tabs row">
            <li class="tab col s6 alipay-tab waves-effect waves-light">
              <a href="#alipay">支付宝</a>
            </li>
            <li class="tab col s6 wechat-tab waves-effect waves-light">
              <a href="#wechat">微 信</a>
            </li>
          </ul>
          <div id="alipay">
            <img
              src="/medias/reward/alipay.jpg"
              class="reward-img"
              alt="支付宝打赏二维码"
            />
          </div>
          <div id="wechat">
            <img
              src="/medias/reward/wechat.png"
              class="reward-img"
              alt="微信打赏二维码"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<script>
  $(function() {
    $(".tabs").tabs();
  });
</script>

            
        </div>
    </div>

    
        <link rel="stylesheet" href="https://cdn.bootcss.com/gitalk/1.6.2/gitalk.min.css">
<link rel="stylesheet" href="/css/my-gitalk.css">

<div class="card gitalk-card" data-aos="fade-up">
    <div class="comment_headling" style="font-size: 20px; font-weight: 700; position: relative; left: 20px; top: 15px; padding-bottom: 5px;">
        <i class="fas fa-comments fa-fw" aria-hidden="true"></i>
        <span>评论</span>
    </div>
    <div id="gitalk-container" class="card-content"></div>
</div>

<script src="https://cdn.bootcss.com/gitalk/1.6.2/gitalk.min.js"></script>
<script>
    let gitalk = new Gitalk({
        clientID: 'f1e60c7afa53a51926b5',
        clientSecret: '2430231be04e68f6ba8ccf331c537cc19f50a0bd',
        repo: 'xkloveme.github.io',
        owner: 'xkloveme',
        admin: "xkloveme",
        id: '2019-10-11T16-00-00',
        distractionFreeMode: false  // Facebook-like distraction free mode
    });

    gitalk.render('gitalk-container');
</script>
    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2019/10/11/2019-10-12-vue-v-xxx-ji-yu-vue-tuo-zhan-de-v-xxx-ku/">
                    <div class="card-image">
                        
                        
                        <img src="https://picsum.photos/600/300" class="responsive-img" alt="基于 Vue拓展的 v-xxx 库">
                        
                        <span class="card-title">基于 Vue拓展的 v-xxx 库</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
君问归期未有期，巴山夜雨涨秋池。 &gt; 何当共剪西窗烛，却话巴山夜雨时。

作为vue轻车熟路的老司机，经常会用到一些指令，vue官方提供的指令又太少，无法满足旺盛的欲望，而每次要写一遍，终日郁郁寡欢，从小就教育我们乐于助人，为了将奉
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2019-10-11
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E5%89%8D%E7%AB%AF/" class="post-category">
                                    前端
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/vue/">
                        <span class="chip bg-color">vue</span>
                    </a>
                    
                    <a href="/tags/GitHub/">
                        <span class="chip bg-color">GitHub</span>
                    </a>
                    
                    <a href="/tags/%E6%8C%87%E4%BB%A4/">
                        <span class="chip bg-color">指令</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2018/08/09/2018-07-10-vue-refs/">
                    <div class="card-image">
                        
                        
                        <img src="https://picsum.photos/600/300" class="responsive-img" alt="Vue中的代理Proxy和$refs">
                        
                        <span class="card-title">Vue中的代理Proxy和$refs</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            前言
最近国内 VPN 限制的严厉的多，一不小心就会被抓去签保证书，为了能和小伙伴联系，也为了能查到相关资讯，了解国内动态，关注权利的猎物老郭特此写博，然而这一切都是免费的！免费的！免费的！（重要的事情讲三遍）

正文开始一、 代理 Pro
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2018-08-09
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E5%89%8D%E7%AB%AF/" class="post-category">
                                    前端
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/vue/">
                        <span class="chip bg-color">vue</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>


<script>
    $('#articleContent').on('copy', function (e) {
        // IE8 or earlier browser is 'undefined'
        if (typeof window.getSelection === 'undefined') return;

        var selection = window.getSelection();
        // if the selection is short let's not annoy our users.
        if (('' + selection).length < Number.parseInt('120')) {
            return;
        }

        // create a div outside of the visible area and fill it with the selected text.
        var bodyElement = document.getElementsByTagName('body')[0];
        var newdiv = document.createElement('div');
        newdiv.style.position = 'absolute';
        newdiv.style.left = '-99999px';
        bodyElement.appendChild(newdiv);
        newdiv.appendChild(selection.getRangeAt(0).cloneContents());

        // we need a <pre> tag workaround.
        // otherwise the text inside "pre" loses all the line breaks!
        if (selection.getRangeAt(0).commonAncestorContainer.nodeName === 'PRE') {
            newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>";
        }

        var url = document.location.href;
        newdiv.innerHTML += '<br />'
            + '来源: 小康之家<br />'
            + '文章作者: xkloveme<br />'
            + '文章链接: <a href="' + url + '">' + url + '</a><br />'
            + '本文章著作权归作者所有，任何形式的转载都请注明出处。';

        selection.selectAllChildren(newdiv);
        window.setTimeout(function () {bodyElement.removeChild(newdiv);}, 200);
    });
</script>


<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>

    
<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


<!-- 代码块折行 -->

<style type="text/css">
code[class*="language-"], pre[class*="language-"] { white-space: pre !important; }
</style>

    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="https://cdn.bootcss.com/tocbot/4.10.0/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            // headingsOffset: -205,
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>



    <footer class="page-footer bg-color">
  <div class="container row center-align">
    <div class="col s12 m8 l8 copy-right">
      Copyright&nbsp;&copy;
      <span id="year">年份</span>
      <a href="http://jixioakang.com" target="_blank">xkloveme</a>
      |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
      <br />
       &nbsp;<i
        class="fas fa-chart-area"
      ></i
      >&nbsp;站点总字数:&nbsp;<span class="white-color"
        >141.5k</span
      >&nbsp;字      
      <span id="busuanzi_container_site_pv">
        |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span
          id="busuanzi_value_site_pv"
          class="white-color"
        ></span
        >&nbsp;次
      </span>
       
      <span id="busuanzi_container_site_uv">
        |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span
          id="busuanzi_value_site_uv"
          class="white-color"
        ></span
        >&nbsp;人
      </span>
      
      <br />
      
      <span id="sitetime">载入运行时间...</span>
      <script>
        function siteTime() {
          window.setTimeout("siteTime()", 1000);
          var seconds = 1000;
          var minutes = seconds * 60;
          var hours = minutes * 60;
          var days = hours * 24;
          var years = days * 365;
          var today = new Date();
          var startYear = "2017";
          var startMonth = "3";
          var startDate = "13";
          var startHour = "0";
          var startMinute = "0";
          var startSecond = "0";
          var todayYear = today.getFullYear();
          var todayMonth = today.getMonth() + 1;
          var todayDate = today.getDate();
          var todayHour = today.getHours();
          var todayMinute = today.getMinutes();
          var todaySecond = today.getSeconds();
          var t1 = Date.UTC(
            startYear,
            startMonth,
            startDate,
            startHour,
            startMinute,
            startSecond
          );
          var t2 = Date.UTC(
            todayYear,
            todayMonth,
            todayDate,
            todayHour,
            todayMinute,
            todaySecond
          );
          var diff = t2 - t1;
          var diffYears = Math.floor(diff / years);
          var diffDays = Math.floor(diff / days - diffYears * 365);
          var diffHours = Math.floor(
            (diff - (diffYears * 365 + diffDays) * days) / hours
          );
          var diffMinutes = Math.floor(
            (diff - (diffYears * 365 + diffDays) * days - diffHours * hours) /
              minutes
          );
          var diffSeconds = Math.floor(
            (diff -
              (diffYears * 365 + diffDays) * days -
              diffHours * hours -
              diffMinutes * minutes) /
              seconds
          );
          if (startYear == todayYear) {
            document.getElementById("year").innerHTML = todayYear;
            document.getElementById("sitetime").innerHTML =
              "本站已安全运行 " +
              diffDays +
              " 天 " +
              diffHours +
              " 小时 " +
              diffMinutes +
              " 分钟 " +
              diffSeconds +
              " 秒";
          } else {
            document.getElementById("year").innerHTML =
              startYear + " - " + todayYear;
            document.getElementById("sitetime").innerHTML =
              "本站已安全运行 " +
              diffYears +
              " 年 " +
              diffDays +
              " 天 " +
              diffHours +
              " 小时 " +
              diffMinutes +
              " 分钟 " +
              diffSeconds +
              " 秒";
          }
        }
        setInterval(siteTime, 1000);
      </script>
      
      <br />
      
    </div>
    <div class="col s12 m4 l4 social-link social-statis">
      
    <a href="https://github.com/xkloveme" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:xkloveme@gmail.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>





    <a href="https://twitter.com/xkloveme" class="tooltipped" target="_blank" data-tooltip="关注我的Twitter: https://twitter.com/xkloveme" data-position="top" data-delay="50">
        <i class="fab fa-twitter"></i>
    </a>









    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>


    </div>
  </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/" + "search.xml", 'searchInput', 'searchResult');
});
</script>
    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="https://cdn.bootcss.com/materialize/1.0.0/js/materialize.min.js"></script>
    <script src="https://cdn.bootcss.com/masonry/4.0.0/masonry.pkgd.min.js"></script>
    <script src="https://cdn.bootcss.com/aos/3.0.0-beta.6/aos.js"></script>
    <script src="https://cdn.bootcss.com/scrollprogress/3.0.2/scrollProgress.min.js"></script>
    <script src="https://cdn.bootcss.com/lightgallery/1.6.11/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    <!-- Global site tag (gtag.js) - Google Analytics -->

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-102352377-2"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag() {
        dataLayer.push(arguments);
    }

    gtag('js', new Date());
    gtag('config', 'UA-102352377-2');
</script>


    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    

    

    
    <script type="text/javascript" src="/libs/background/ribbon-dynamic.js" async="async"></script>
    
    
    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
